<?php

declare(strict_types=1);
/**
 * 
 */
namespace WanZ\App\User\Consumer;

use Hyperf\Context\Context;
use WanZ\App\Utils\HttpRequest;

abstract class AbstractConsumer
{
    protected $data = [];

    /**
     * @return HttpRequest
     */
    public function httpRequest(): HttpRequest
    {
        return make(HttpRequest::class);
    }

    public function _(array $params): AbstractConsumer
    {
        $this->data += $params;
        $this->data['company_id'] = $this->getCompanyId();
        return $this;
    }

    /**
     * 获取Url
     *
     * @param string $serviceUrlName
     * @return string
     */
    public function getUrl(string $serviceUrlName = 'public'): string
    {
        return config('providers.'.$serviceUrlName);
    }

    /**
     * 获取请求的公司ID
     * 
     * @return int
     */
    public function getCompanyId(): int
    {
        if (!isset($this->data['company_id']) || empty($this->data['company_id'])) {
            return (int) Context::get('company_id', 0);
        }

        return (int) $this->data['company_id'];
    }    

    /**
     * 获取请求公司类型 default | car
     * 
     * @return mixed|string
     */
    public function getType()
    {
        return Context::get('platformType', 'default');
    }

}